# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from common.utils.config import ConfigUtil
from apps.admin.schemas.setting import policy_schema as schema


class PolicyService:
    """ 协议配置服务类 """

    @classmethod
    async def detail(cls) -> schema.PolicyDetailVo:
        """
        协议配置详情。

        Returns:
            schema.PolicyDetailVo: 协议配置详情Vo。

        Author:
            zero
        """
        conf = await ConfigUtil.get("policy") or {}
        return schema.PolicyDetailVo(
            service=conf.get("service", ""),
            private=conf.get("private", ""),
            payment=conf.get("payment", "")
        )

    @classmethod
    async def save(cls, post: schema.PolicyDetailVo):
        """
        协议配置保存。

         Args:
            post (schema.PolicyDetailVo): 协议配置参数。

        Author:
            zero
        """
        await ConfigUtil.set("policy", "service", post.service)
        await ConfigUtil.set("policy", "private", post.private)
        await ConfigUtil.set("policy", "payment", post.payment)
